package com.example.dormitory_system.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.example.dormitory_system.domain.R;
import com.example.dormitory_system.domain.TableDataInfo;
import com.github.pagehelper.PageInfo;


import java.util.List;

public class BaseController {

    public R<Void> toR(int rows) {
        return rows > 0? R.ok() : R.fail();
    }
//This method returns an R<Void> object based on the boolean parameter result
    public R<Void> toR(boolean result) {
        return result ? R.ok() : R.fail();
    }

    public TableDataInfo getDataTable(List<?> data) {
        if (CollectionUtil.isEmpty(data)) {
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(data,new PageInfo<>(data).getTotal());
    }

    public TableDataInfo getDataTable(List<?> data, long total) {
        if (CollectionUtil.isEmpty(data)) {
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(data,total);
    }
}
